from django import template

register = template.Library()

@register.filter
def split(value, arg):
    """
    将字符串按指定分隔符分割
    用法: {{ value|split:"," }}
    """
    return [x.strip() for x in value.split(arg)] if value else []

@register.filter
def trim(value):
    """
    去除字符串首尾空格
    用法: {{ value|trim }}
    """
    return value.strip() if value else '' 

@register.filter
def get_field_value(data, field_id):
    """
    从表单提交数据中获取指定字段的值
    """
    return data.get(f'field_{field_id}') 